using System;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace CSW.Framework.UI.DevEx.Forms
{
    /// <summary>
    /// DXGetDateRangeForm
    /// </summary>
    public sealed partial class DXGetDateRangeForm : XtraForm
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="DXGetDateRangeForm"/> class.
        /// </summary>
        public DXGetDateRangeForm(DateTime startDate, DateTime endDate)
        {
            InitializeComponent();

            layoutControlItem2.Text = "Start Date";
            layoutControlItem1.Text = "End Date";

            dateEdit1.EditValue = startDate;
            dateEdit2.EditValue = endDate;
        }

        private void cmdCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void cmdOK_Click(object sender, EventArgs e)
        {
            DateTime startDate = (DateTime)dateEdit1.EditValue;
            DateTime endDate = (DateTime)dateEdit2.EditValue;
            if (endDate < startDate)
            {
                MessageBox.Show("End Date is before Start Date.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            DialogResult = DialogResult.OK;
            Close();
        }

        /// <summary>
        /// Gets the date.
        /// </summary>
        /// <value>The date.</value>
        public DateRangeEventArgs Date
        {
            get 
            {
                if (DialogResult == DialogResult.OK)
                {
                    DateRangeEventArgs e = new DateRangeEventArgs((DateTime)dateEdit1.EditValue, (DateTime)dateEdit2.EditValue);
                    return e;
                }
                else
                {
                    return null;
                }
            }
        }
    }
}